<?php
include_once("../Dao/db.php");
include_once("../Service/WebClass/report/Remove.php");
Class KeyWord
{
	// 表示形式
	var $reportAxis = "id";
	
	// 開始時間
	var $fromDate;
	// 結束時間
	var $toDate;
	
	// 詳細検索条件表示フラグ
	var $searchDetailHid = "display:none;";
	
	var $searchCol = "key_Id";
	
	var $searchText;
	
	var $searchType = "0";
	
	var $filterCol = "impression";
	
	var $filterValue;
	
	var $filterType = "1";
	
	var $filter2Col = "sponsored_maxbid";
	
	var $filter2Value;
	
	var $filter2Type = "1";
	
	var $filter3Col = "impression";
	
	var $filter3Value;
	
	var $filter3Type = "1";
	
	// 媒体
	var $searchMediaSelect = "0";
	
	// キャンペーン
	var $searchCampaignSelect = "0";
	
	// グループ
	var $searchBannerSelect = "0";
	
	// 同期状態
	var $searchSync = "0";
	
	// 図種類
	var $graphType = "0";
	
	// 指標1
	var $graphCol1 = "impression";
	
	// 指標2
	var $graphCol2 = "impression";
	
	// グラフサイズ
	var $graphSize = "0";
	
	// ビュー
	var $selectView = "1";
	
	// 成果地点
	var $selectPoint = 0;
	
	// データない非表示
	var $hideZero;
	
	// 削除済みも表示
	var $showDeleted;
	
	// 成果地点リスト
	var $cvPointList = "";
	
	// キャンペーンリスト
	var $campaignOptionList = "";
	
	// 媒体リスト
	var $mediaOptionList = "";
	
	// グループリスト
	var $adgroupOptionList = "";	
	
	var $tableList = "";
	
	var $errorMsg = "";
	
	var $fromToRowHtml = "";
	
	var $allRowHtml = "";
	
	var $pageLinkHtml = "";
	
	var $nowPageNum = 1;
	
	var $maxpage ;
	
	// ABCD分析利用する平均CPA
	var $avgCPA;
	
	// ABCD検索条件
	var $select_ABCD="0";
	
	// 毎ページのレコード数
	var $RECORD_NUMBER_PER_PAGE = 20;
	
	function MyTask()
	{
		// 初期化の場合
		if($_POST["act"] == null)
		{
			$this->getCvPointOptionList();
			$this->getMediaOptionList();
			$this->getCampaignOptionList();
			if($_GET["displayFlg"] == "1")
			{
				$this->fromDate = $_GET["fromDate"];
				$this->toDate = $_GET["toDate"];
				if($_GET["mediaId"] != "0" && $_GET["mediaId"] != null)
				{			
					$this->searchMediaSelect = $_GET["mediaId"];
				}
				if($_GET["campaignId"] != "0" && $_GET["campaignId"] != null)
				{
					$this->searchCampaignSelect = $_GET["campaignId"];
					$this->getGroupOptionList();
				}
				if($_GET["adgroupId"] != "0" && $_GET["adgroupId"] != null)
				{
					$this->searchBannerSelect = $_GET["adgroupId"];
				}										
				$this->searchDetailHid = "display:block;";
			}
			// キャンペーンページから遷移するの場合
			else if($_GET["campaignId"] != null)
			{
				$this->fromDate = $_GET["fromDate"];
				$this->toDate = $_GET["toDate"];
				$this->searchCampaignSelect = $_GET["campaignId"];
				$this->setMediaList($this->searchCampaignSelect);
				$this->getGroupOptionList();				
				$this->searchBannerSelect = $_GET["adgroupId"];				
				$this->searchDetailHid = "display:block;";
			}		
			$this->getTableList($this->nowPageNum);			
		}
		// 検索の場合
		else if($_POST["act"] == "submit")
		{
			$this->iniForm();
			$this->getCvPointOptionList();
			$this->getMediaOptionList();
			$this->getCampaignOptionList();
			$this->getGroupOptionList();
			$this->getTableList($this->nowPageNum);
		}
		else if($_POST["act"] == "getGroup")
		{
			$this->iniForm();
			$this->getCvPointOptionList();
			$this->getMediaOptionList();
			$this->getCampaignOptionList();
			$this->setMediaList($this->searchCampaignSelect);			
			$this->getGroupOptionList();
			$this->searchBannerSelect = "0";	
			$this->getTableList($this->nowPageNum);
		}
		else if($_POST["act"] == "csv")
		{
			$this->iniForm();
			$this->getCvPointOptionList();
			$this->getMediaOptionList();
			$this->getCampaignOptionList();
			$this->getGroupOptionList();
			$this->outputCsv();
		}
		else if($_POST["act"] == "delete")
		{
			$message = removeKeyword($_POST["keywordIdList"]);	
			$this->iniForm();		
			$this->getCvPointOptionList();
			$this->getMediaOptionList();
			$this->getCampaignOptionList();
			$this->getGroupOptionList();
			$this->getTableList($this->nowPageNum);
			echo "<script>alert(\"$message\");</script>";
		}					
	}
	
	// 成果地点マスタデータを取得する	
	function getCvPointOptionList()
	{
		session_start();
		$sql = "select id,name from cvpoint where memberId=".$_SESSION["memberId"];
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if ($rows > 0)
		{
			// i=1は「すべて」の対応
			for ($i=1;$i<$rows+1;$i++)
			{
				$data = mysql_fetch_row($result);				
				$this->cvPointList = $this->cvPointList."<option id=".$i." value=".$data[0].">".$data[1]."</option>";
			}			
		}
	}
	
	// 媒体リストを取得する
	function getMediaOptionList()
	{
		$sql = "select id,name from listingmst";
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if($rows >0)
		{
			for($i=0;$i<$rows;$i++)
			{
				$data = mysql_fetch_row($result);
				$this->mediaOptionList = $this->mediaOptionList."<option id=".$i." value=".$data[0].">".$data[1]."</option>";
			}
		}
	}
	
	function getCampaignOptionList()
	{
		session_start();
		$sql = "select camp_ID,name from campaign where campaign.status <> 9 and memberId=".$_SESSION["memberId"];
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if ($rows > 0)
		{
			// i=1は「指定なし」の対応
			for ($i=1;$i<$rows+1;$i++)
			{
				$data = mysql_fetch_row($result);				
				$this->campaignOptionList = $this->campaignOptionList."<option id=".$i." value=".$data[0].">".$data[1]."</option>";
			}			
		}		
	}
	
	// 広告グループリストを取得する
	function getGroupOptionList()
	{
		session_start();
		$sql = "select adGr_ID,name from adgroup where adgroup.status <> 9 and memberId=".$_SESSION["memberId"]." and camp_ID=".$this->searchCampaignSelect;
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if ($rows > 0)
		{
			// i=1は「指定なし」の対応
			for ($i=1;$i<$rows+1;$i++)
			{
				$data = mysql_fetch_row($result);				
				$this->adgroupOptionList = $this->adgroupOptionList."<option id=".$i." value=".$data[0].">".$data[1]."</option>";
			}			
		}
	
	}
	
	function KeyWord()
	{
		$this->fromDate = date("Y-m-01",time());
		$this->toDate = date("Y-m-d",time());
	}
	
	function iniForm()
	{
		// 表示形式
		$this->reportAxis = $_POST["report_axis"];
		// 媒体
		$this->searchMediaSelect = $_POST["search_media_select"];
		
		// キャンペーン
		if($_POST["isMediaSelectClick"] == "1")
		{
			$this->searchCampaignSelect = "0";
			// 広告グループ
			$this->searchBannerSelect = "0";		
		}
		else
		{
			$this->searchCampaignSelect = $_POST["search_campaign_select"];
			// 広告グループ
			$this->searchBannerSelect = $_POST["search_banner_select"];			
		}
				
		// 開始日
		$this->fromDate = $_POST["from_date"];
		
		// 結束日
		$this->toDate = $_POST["to_date"];
		
		// 詳細検索条件表示フラグ
		$this->searchDetailHid = $_POST["search_detail_hid"];
		
		$this->searchCol = $_POST["search_col"];
		
		$this->searchText = $_POST["search_text"];
		
		$this->searchType = $_POST["search_type"];
		
		$this->filterCol = $_POST["filter_col"];
		
		$this->filterValue = $_POST["filter_value"];
		
		$this->filterType = $_POST["filter_type"];
		
		$this->filter2Col = $_POST["filter2_col"];
		
		$this->filter2Value = $_POST["filter2_value"];
		
		$this->filter2Type = $_POST["filter2_type"];

		$this->filter3Col = $_POST["filter3_col"];
		
		$this->filter3Value = $_POST["filter3_value"];
		
		$this->filter3Type = $_POST["filter3_type"];
				
		// 同期状態
		$this->searchSync = $_POST["search_sync"];
		
		// 図種類
		$this->graphType = $_POST["graph_type"];
		
		// 指標1
		$this->graphCol1 = $_POST["graph_col1"];
		
		// 指標2
		$this->graphCol2 = $_POST["graph_col2"];
		
		// グラフサイズ
		$this->graphSize = $_POST["graph_size"];
		
		// ビュー
		$this->selectView = $_POST["select_view"];
		
		// ougi ABCD 20081213 表示形式は「キーワード別」以外、且つビューは「ABCD分析」の場合、「標準ビー」に設定する
		if($this->reportAxis != "id" && $this->selectView == "9")
		{
			$this->selectView = 1;
		}
		
		// 成果地点
		$this->selectPoint = $_POST["select_point"];
		
		// データない非表示
		$this->hideZero = $_POST["hide_zero"];
		
		// 削除済みも表示
		$this->showDeleted = $_POST["show_deleted"];
		
		$this->nowPageNum = $_POST["nowPage"];	
		
		// ougi ABCD 20081213
		if(!isset($_POST["avgCPA"]) && $this->selectView == "9") 
		{
			$this->avgCPA = $this->getAvgCPA();
			//echo  "Q:".$this->avgCPA;
		}
		else
		{
			$this->avgCPA = $_POST["avgCPA"];
			//echo  "T:".$this->avgCPA;
		}
			
		if(isset($_POST["select_ABCD"]))
		{
			$this->select_ABCD = $_POST["select_ABCD"];	
		}
		else
		{
			$this->select_ABCD = "0";
		}		
	}
	
	function getSelectSql()
	{
		// 表示形式を判断する
		// クリエイティブ別の場合
		if($this->reportAxis == "id")
		{
			if($this->selectView != "3")
			{
				$sql = 		"select keyword.key_Id,keyword.text keywordtext,campaign.name campaignname,campaign.camp_Id campaignid,adgroup.adGr_ID,adgroup.name adgroupname,adgroup.listingType,keyword.sync,keyword.status,keyword.paused,keyword.maxcpc, ";
				$sql = $sql."sum(keywordsreport.impression) impression,sum(keywordsreport.clickCnt) clickCnt,100*sum(keywordsreport.clickCnt)/sum(keywordsreport.impression) ctr,sum(keywordsreport.cost)/sum(keywordsreport.clickCnt) cpc,sum(keywordsreport.cost) cost,avg(keywordsreport.position) position,";
				$sql = $sql."sum(keywordscvreport.cv) cv,100*sum(keywordscvreport.cv)/sum(keywordsreport.clickCnt) cvr,sum(keywordsreport.cost)/sum(keywordscvreport.cv) cpa,1000*sum(keywordsreport.cost)/sum(keywordsreport.impression) cpm,sum(keywordscvreport.sales)/sum(keywordsreport.cost) roas,sum(keywordscvreport.sales) sales,";
				$sql = $sql."sum(keywordscvreport.sales)/sum(keywordscvreport.cv) salesValue,avg(keywordscvreport.clickCvSpan) clickCvSpan,sum(keywordscvreport.directCvCnt) directCvCnt,sum(keywordscvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(keywordscvreport.asistCvCnt) asistCvCnt,sum(keywordscvreport.postCvCnt) postCvCnt,avg(keywordsreport.position) ";
				
				// ougi ABCD 20081213
				if($this->selectView == "9")
				{
					$sql = $sql." , case when sum(keywordscvreport.cv) > 0  then ";
					$sql = $sql."  case when  sum(keywordsreport.cost)/sum(keywordscvreport.cv) > ".$this->avgCPA." then 'B' else 'A'  end ";
					$sql = $sql."  else case when sum(keywordsreport.cost) < ".$this->avgCPA." then 'D' else 'C' end ";
					
					$sql = $sql." end ABCD ";
				}
				
				$sql = $sql." from campaign,adgroup,((keyword left join keywordscvreport on keyword.key_Id = keywordscvreport.keyword_id  ";
				$sql = $sql."and TO_DAYS('".$this->fromDate."')<=TO_DAYS(keywordscvreport.date) ";
				// 成果地点の条件を追加する
				// すべて以外の場合
				if($this->selectPoint != "0")
				{
					$sql = $sql."and keywordscvreport.cvId = ".$_POST["select_point"]." ";
				}
				else
				{
					$sql = $sql."and keywordscvreport.cvId = -1 ";
				}				
				$sql = $sql."and TO_DAYS(keywordscvreport.date)<=TO_DAYS('".$this->toDate."')) " ;
				$sql = $sql."left join keywordsreport ";
				$sql = $sql."on keywordscvreport.date = keywordsreport.date ";
				$sql = $sql."and keywordscvreport.memberid = keywordsreport.memberId ";	
				$sql = $sql."and keywordscvreport.listingtype = keywordsreport.listingType ";
				$sql = $sql."and keywordscvreport.campaign_id = keywordsreport.campaign_Id ";
				$sql = $sql."and keywordscvreport.adGroup_id = keywordsreport.adGroup_Id ";
				$sql = $sql."and keywordscvreport.keyword_id = keywordsreport.keyword_id) ";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do 
				//$sql = 		"select AdReport.campaignId campaignId,Campaign.name name,Campaign.status status,Campaign.listingType,Campaign.sync,AdReport.cvName, ";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}
		// 日別
		else if ($this->reportAxis == "d")
		{
			if($this->selectView != "3")
			{
				$sql = 		"select DATE_FORMAT(keywordsreport.date,'%Y%m%d') date,";
				$sql = $sql."sum(keywordsreport.impression) impression,sum(keywordsreport.clickCnt) clickCnt,100*sum(keywordsreport.clickCnt)/sum(keywordsreport.impression) ctr,sum(keywordsreport.cost)/sum(keywordsreport.clickCnt) cpc,sum(keywordsreport.cost) cost,avg(keywordsreport.position) position,";
				$sql = $sql."sum(keywordscvreport.cv) cv,100*sum(keywordscvreport.cv)/sum(keywordsreport.clickCnt) cvr,sum(keywordsreport.cost)/sum(keywordscvreport.cv) cpa,1000*sum(keywordsreport.cost)/sum(keywordsreport.impression) cpm,sum(keywordscvreport.sales)/sum(keywordsreport.cost) roas,sum(keywordscvreport.sales) sales,";
				$sql = $sql."sum(keywordscvreport.sales)/sum(keywordscvreport.cv) salesValue,avg(keywordscvreport.clickCvSpan) clickCvSpan,sum(keywordscvreport.directCvCnt) directCvCnt,sum(keywordscvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(keywordscvreport.asistCvCnt) asistCvCnt,sum(keywordscvreport.postCvCnt) postCvCnt,avg(keywordsreport.position) ";
				$sql = $sql."from (keyword left join keywordscvreport on keyword.key_Id = keywordscvreport.keyword_id)  ";
				$sql = $sql."left join keywordsreport ";
				$sql = $sql."on keywordscvreport.date = keywordsreport.date ";
				$sql = $sql."and keywordscvreport.memberid = keywordsreport.memberId ";	
				$sql = $sql."and keywordscvreport.listingtype = keywordsreport.listingType ";
				$sql = $sql."and keywordscvreport.campaign_id = keywordsreport.campaign_Id ";
				$sql = $sql."and keywordscvreport.adGroup_id = keywordsreport.adGroup_Id ";
				$sql = $sql."and keywordscvreport.keyword_id = keywordsreport.keyword_id ";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do 
				//$sql = 		"select DATE_FORMAT(date,'%Y%m%d') date,AdReport.cvName cvName,";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			if($this->selectView != "3")
			{
				$sql = 		"select weekly,";
				$sql = $sql."sum(keywordsreport.impression) impression,sum(keywordsreport.clickCnt) clickCnt,100*sum(keywordsreport.clickCnt)/sum(keywordsreport.impression) ctr,sum(keywordsreport.cost)/sum(keywordsreport.clickCnt) cpc,sum(keywordsreport.cost) cost,avg(keywordsreport.position) position,";
				$sql = $sql."sum(keywordscvreport.cv) cv,100*sum(keywordscvreport.cv)/sum(keywordsreport.clickCnt) cvr,sum(keywordsreport.cost)/sum(keywordscvreport.cv) cpa,1000*sum(keywordsreport.cost)/sum(keywordsreport.impression) cpm,sum(keywordscvreport.sales)/sum(keywordsreport.cost) roas,sum(keywordscvreport.sales) sales,";
				$sql = $sql."sum(keywordscvreport.sales)/sum(keywordscvreport.cv) salesValue,avg(keywordscvreport.clickCvSpan) clickCvSpan,sum(keywordscvreport.directCvCnt) directCvCnt,sum(keywordscvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(keywordscvreport.asistCvCnt) asistCvCnt,sum(keywordscvreport.postCvCnt) postCvCnt,avg(keywordsreport.position) ";
				$sql = $sql."from (keyword left join keywordscvreport on keyword.key_Id = keywordscvreport.keyword_id)  ";
				$sql = $sql."left join keywordsreport ";
				$sql = $sql."on keywordscvreport.date = keywordsreport.date ";
				$sql = $sql."and keywordscvreport.memberid = keywordsreport.memberId ";	
				$sql = $sql."and keywordscvreport.listingtype = keywordsreport.listingType ";
				$sql = $sql."and keywordscvreport.campaign_id = keywordsreport.campaign_Id ";
				$sql = $sql."and keywordscvreport.adGroup_id = keywordsreport.adGroup_Id ";
				$sql = $sql."and keywordscvreport.keyword_id = keywordsreport.keyword_id ";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
				//$sql = 		"select weekly,AdReport.cvName cvName,";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{			
			if($this->selectView != "3")
			{
				$sql = 		"select dayOfTheWeek,";
				$sql = $sql."sum(keywordsreport.impression) impression,sum(keywordsreport.clickCnt) clickCnt,100*sum(keywordsreport.clickCnt)/sum(keywordsreport.impression) ctr,sum(keywordsreport.cost)/sum(keywordsreport.clickCnt) cpc,sum(keywordsreport.cost) cost,avg(keywordsreport.position) position,";
				$sql = $sql."sum(keywordscvreport.cv) cv,100*sum(keywordscvreport.cv)/sum(keywordsreport.clickCnt) cvr,sum(keywordsreport.cost)/sum(keywordscvreport.cv) cpa,1000*sum(keywordsreport.cost)/sum(keywordsreport.impression) cpm,sum(keywordscvreport.sales)/sum(keywordsreport.cost) roas,sum(keywordscvreport.sales) sales,";
				$sql = $sql."sum(keywordscvreport.sales)/sum(keywordscvreport.cv) salesValue,avg(keywordscvreport.clickCvSpan) clickCvSpan,sum(keywordscvreport.directCvCnt) directCvCnt,sum(keywordscvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(keywordscvreport.asistCvCnt) asistCvCnt,sum(keywordscvreport.postCvCnt) postCvCnt,avg(keywordsreport.position) ";
				$sql = $sql."from (keyword left join keywordscvreport on keyword.key_Id = keywordscvreport.keyword_id)  ";
				$sql = $sql."left join keywordsreport ";
				$sql = $sql."on keywordscvreport.date = keywordsreport.date ";
				$sql = $sql."and keywordscvreport.memberid = keywordsreport.memberId ";	
				$sql = $sql."and keywordscvreport.listingtype = keywordsreport.listingType ";
				$sql = $sql."and keywordscvreport.campaign_id = keywordsreport.campaign_Id ";
				$sql = $sql."and keywordscvreport.adGroup_id = keywordsreport.adGroup_Id ";
				$sql = $sql."and keywordscvreport.keyword_id = keywordsreport.keyword_id ";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
				//$sql = 		"select dayOfTheWeek,AdReport.cvName cvName,";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			if($this->selectView != "3")
			{
				$sql = 		"select DATE_FORMAT(keywordsreport.date,'%Y-%m') month,";
				$sql = $sql."sum(keywordsreport.impression) impression,sum(keywordsreport.clickCnt) clickCnt,100*sum(keywordsreport.clickCnt)/sum(keywordsreport.impression) ctr,sum(keywordsreport.cost)/sum(keywordsreport.clickCnt) cpc,sum(keywordsreport.cost) cost,avg(keywordsreport.position) position,";
				$sql = $sql."sum(keywordscvreport.cv) cv,100*sum(keywordscvreport.cv)/sum(keywordsreport.clickCnt) cvr,sum(keywordsreport.cost)/sum(keywordscvreport.cv) cpa,1000*sum(keywordsreport.cost)/sum(keywordsreport.impression) cpm,sum(keywordscvreport.sales)/sum(keywordsreport.cost) roas,sum(keywordscvreport.sales) sales,";
				$sql = $sql."sum(keywordscvreport.sales)/sum(keywordscvreport.cv) salesValue,avg(keywordscvreport.clickCvSpan) clickCvSpan,sum(keywordscvreport.directCvCnt) directCvCnt,sum(keywordscvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(keywordscvreport.asistCvCnt) asistCvCnt,sum(keywordscvreport.postCvCnt) postCvCnt,avg(keywordsreport.position) ";
				$sql = $sql."from (keyword left join keywordscvreport on keyword.key_Id = keywordscvreport.keyword_id)  ";
				$sql = $sql."left join keywordsreport ";
				$sql = $sql."on keywordscvreport.date = keywordsreport.date ";
				$sql = $sql."and keywordscvreport.memberid = keywordsreport.memberId ";	
				$sql = $sql."and keywordscvreport.listingtype = keywordsreport.listingType ";
				$sql = $sql."and keywordscvreport.campaign_id = keywordsreport.campaign_Id ";
				$sql = $sql."and keywordscvreport.adGroup_id = keywordsreport.adGroup_Id ";
				$sql = $sql."and keywordscvreport.keyword_id = keywordsreport.keyword_id ";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
				//$sql = 		"select DATE_FORMAT(adcvreport.date,'%Y-%m') month,AdReport.cvName cvName,";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}			
		
		return $sql;		
	}
	
	function getLikeSql($text,$type)
	{
		// 全部一致の場合
		if($type == "0")
		{
			return " = '".$text."' ";
		}
		// 部分一致の場合
		if($type == "1")
		{
			return " like binary '%$text%' ";
		}
	}
	
	function getWhereSqlForCreative()
	{		
		if($this->searchDetailHid == "display:none")
		{
		}
		// 詳細検索がある場合
		else
		{
			if(trim($this->searchText) != null && trim($this->searchText) != "")
			{
				$sql = $sql."and keyword.".$this->searchCol.$this->getLikeSql(trim($this->searchText),$this->searchType)." ";
			}
			// 媒体の条件を追加する
			// 指定した場合
			if($this->searchMediaSelect != "0")
			{
				$sql = $sql."and keyword.listingType=".$this->searchMediaSelect." ";
			}
			// キャンペーンの条件を追加する
			// 指定の場合
			if($this->searchCampaignSelect != "0")
			{
				$sql = $sql."and keyword.camp_Id= ".$this->searchCampaignSelect." ";
			}
			// 広告グループの条件を追加する
			if($this->searchBannerSelect != "0")
			{
				$sql = $sql."and keyword.adGr_Id=".$this->searchBannerSelect." ";
			}
			// 入札額の条件を追加する
			if($this->filter2Value !="")
			{
				// 以下の場合
				if($this->filter2Type == "2")
				{
					$sql = $sql."and keyword.maxcpc <=".$this->filter2Value." ";
				}
				// 以上の場合
				else
				{
					$sql = $sql."and keyword.maxcpc >=".$this->filter2Value." ";
				}
			}		
			// 同期状態の条件を追加する
			// 更新待ちの場合
			if($this->searchSync == "2")
			{
				$sql = $sql."and keyword.sync=2 ";
			}
			// 同期済の場合
			else if($this->searchSync == "1")
			{
				$sql = $sql."and keyword.sync=1 ";			
			}
			// エラーの場合
			else if($this->searchSync == "3")
			{
				$sql = $sql."and keyword.sync=3 ";			
			}
		}
		// 削除済みも表示の条件を追加する
		// 削除非表示
		if($this->showDeleted != "1")
		{
		$sql = $sql."and keyword.status <> 9 ";
		}	
		
		// ougi ABCD 20081213
		if($this->selectView == "9")
		{
			$sql = $sql."and keyword.status <> 9 ";
		}	
		return $sql;
	}
	
	function getWhereSql()
	{
		// 詳細検索条件のフラグを判断する
		// 詳細検索がない場合
		if($this->searchDetailHid == "display:none")
		{
			$sql = "and TO_DAYS('".$this->fromDate."')<=TO_DAYS(keywordscvreport.date) and TO_DAYS(keywordscvreport.date)<=TO_DAYS('".$this->toDate."') ";
		}
		// 詳細検索がある場合
		else
		{
			$sql = "and TO_DAYS('".$this->fromDate."')<=TO_DAYS(keywordscvreport.date) and TO_DAYS(keywordscvreport.date)<=TO_DAYS('".$this->toDate."') ";
			if(trim($this->searchText) != null && trim($this->searchText) != "")
			{
				$sql = $sql."and keyword.".$this->searchCol.$this->getLikeSql(trim($this->searchText),$this->searchType)." ";
			}
			// 媒体の条件を追加する
			// 指定した場合
			if($this->searchMediaSelect != "0")
			{
				$sql = $sql."and keyword.listingType=".$this->searchMediaSelect." ";
			}
			// キャンペーンの条件を追加する
			// 指定の場合
			if($this->searchCampaignSelect != "0")
			{
				$sql = $sql."and keyword.camp_Id= ".$this->searchCampaignSelect." ";
			}
			// 広告グループの条件を追加する
			if($this->searchBannerSelect != "0")
			{
				$sql = $sql."and keyword.adGr_Id=".$this->searchBannerSelect." ";
			}
			// 入札額の条件を追加する
			if($this->filter2Value !="")
			{
				// 以下の場合
				if($this->filter2Type == "2")
				{
					$sql = $sql."and keyword.maxcpc <=".$this->filter2Value." ";
				}
				// 以上の場合
				else
				{
					$sql = $sql."and keyword.maxcpc >=".$this->filter2Value." ";
				}
			}					
			// 同期状態の条件を追加する
			// 更新待ちの場合
			if($this->searchSync == "2")
			{
				$sql = $sql."and keyword.sync=2 ";
			}
			// 同期済の場合
			else if($this->searchSync == "1")
			{
				$sql = $sql."and keyword.sync=1 ";			
			}
			// エラーの場合
			else if($this->searchSync == "3")
			{
				$sql = $sql."and keyword.sync=3 ";			
			}
		}
		// 成果地点の条件を追加する
		// すべて以外の場合
		if($this->selectPoint != "0")
		{
			$sql = $sql."and keywordscvreport.cvId = ".$this->selectPoint." ";
		}
		else
		{
			$sql = $sql."and keywordscvreport.cvId = -1 ";
		}
		
		// 削除済みも表示の条件を追加する
		// 削除非表示
		if($this->showDeleted != "1")
		{
			$sql = $sql."and keyword.status <> 9 ";
		}
				
		return $sql;
	}	
	
	function getGroupSql()
	{
		// キーワード別
		if($this->reportAxis == "id")
		{
			$sql = "group by keywordtext,keyword.key_Id ";
		}
		// 日別
		if ($this->reportAxis == "d")
		{
			// 成果地点別の場合
			if($this->selectView == "3")
			{
				$sql = "group by date,cvName ";
			} 
			else
			{
				$sql = "group by date ";
			}
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			// 成果地点別の場合
			if($this->selectView == "3")
			{
				$sql = "group by weekly,cvName ";
			}
			else
			{
				$sql = "group by weekly ";
			}
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{
			// 成果地点別の場合
			if($this->selectView == "3")
			{
				$sql = "group by dayOfTheWeek,cvName";
			}
			else
			{
				$sql = "group by dayOfTheWeek ";
			}
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			// 成果地点別の場合
			if($this->selectView == "3")
			{
				$sql = "group by month,cvName ";
			}
			else
			{
				$sql = "group by month ";
			}
		}			
		return $sql;
	}
	
	function getHavingSql()
	{
		// 詳細検索がない場合
		if($this->searchDetailHid == "display:none")
		{
		}
		else
		{
			// filter_colとfilter3_colがあるの場合
			if(trim($this->filterValue) != null && trim($this->filterValue) != "" &&
			   trim($this->filter3Value) != null && trim($this->filter3Value) != "")
			{
				// filterTypeが以上の場合
				if($this->filterType == "1")
				{
					$sql = "having (".$this->getHavingFilter($this->filterCol).">=".trim($this->filterValue).") ";
				}
				// filterTypeが以下の場合
				else
				{
					$sql = "having (".$this->getHavingFilter($this->filterCol)."<=".trim($this->filterValue).") ";
				}			
				// filter3Typeが以上の場合
				if($this->filter3Type == "1")
				{
					$sql = $sql."and (".$this->getHavingFilter($this->filter3Col).">=".trim($this->filter3Value).") ";
				}
				// filter3Typeが以下の場合
				else
				{
					$sql = $sql."and (".$this->getHavingFilter($this->filter3Col)."<=".trim($this->filter3Value).") ";
				}
				//return $sql;						
			}
			// filter_colとfilter3_colが全部入力しません
			else if((trim($this->filterValue) == null || trim($this->filterValue) == "") &&
			   (trim($this->filter3Value) == null || trim($this->filter3Value) == ""))
			{
				$sql = " ";
			}
			else
			{
				// filter_colの条件を追加する
				if(trim($this->filterValue) != null && trim($this->filterValue) != "")
				{
					// filterTypeが以上の場合
					if($this->filterType == "1")
					{
						$sql = "having (".$this->getHavingFilter($this->filterCol).">=".trim($this->filterValue).") ";
					}
					// filterTypeが以下の場合
					else
					{
						$sql = "having (".$this->getHavingFilter($this->filterCol)."<=".trim($this->filterValue).") ";
					}
					//return $sql;							
				}
				// filter3_colの条件を追加する
				else
				{
					// filter3_colの条件を追加する
					if(trim($this->filter3Value) != null && trim($this->filter3Value) != "")
					{
						// filter3Typeが以上の場合
						if($this->filter3Type == "1")
						{
							$sql = "having (".$this->getHavingFilter($this->filter3Col).">=".trim($this->filter3Value).") ";
						}
						// filter3Typeが以下の場合
						else
						{
							$sql = "having (".$this->getHavingFilter($this->filter3Col)."<=".trim($this->filter3Value).") ";
						}
						//return $sql;			
					}	
				}					
			}	
		}
		
		if($this->selectView == "9" && $this->select_ABCD != "0")
		{
			if(strpos($sql, "having")===false)
			{
				$sql = $sql." having ABCD='".$this->select_ABCD."'";
			}
			else
			{
				$sql = $sql." and ABCD='".$this->select_ABCD."'";
			}
		}
		return $sql;
		
	}
	
	function getOrderSql()
	{
		$sql = "";
		// キーワード別
		if($this->reportAxis == "id")
		{
			$sql = "order by keywordtext ";
		}
		// 日別
		if ($this->reportAxis == "d")
		{
			$sql = "order by date ";
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			$sql = "order by weekly ";
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{
			$sql = "order by dayOfTheWeek ";
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			$sql = "order by month ";
		}		
		return $sql;
	}
	
	function getTableList($pageNumb)
	{		
		$fromRow = ($pageNumb-1) * $this->RECORD_NUMBER_PER_PAGE;
		$sql = $this->getSelectSql();
		// クリエイティブ別の場合
		if($this->reportAxis == "id")
		{
			session_start();
			$sql = $sql."where campaign.camp_ID = adgroup.camp_ID ";
			$sql = $sql."and adgroup.adGr_ID = keyword.adGr_ID ";						
			$sql = $sql."and keyword.memberId = ".$_SESSION["memberId"]." ";
			$sql = $sql.$this->getWhereSqlForCreative();
		}
		else
		{
			$sql = $sql."where keyword.memberId = ".$_SESSION["memberId"]." ";			
			$sql = $sql.$this->getWhereSql();			
		}
		$sql = $sql.$this->getGroupSql();
		$sql = $sql.$this->getHavingSql();
		$sql = $sql.$this->getOrderSql();			
		$sql = $sql."limit ".$fromRow.",".$this->RECORD_NUMBER_PER_PAGE;
		$totalSql = $this->getSelectSql();
		// クリエイティブ別の場合
		if($this->reportAxis == "id")
		{
			session_start();
			$totalSql = $totalSql."where campaign.camp_ID = adgroup.camp_ID ";
			$totalSql = $totalSql."and adgroup.adGr_ID = keyword.adGr_ID ";						
			$totalSql = $totalSql."and keyword.memberId = ".$_SESSION["memberId"]." ";
			$totalSql = $totalSql.$this->getWhereSqlForCreative();
		}
		else
		{
			$totalSql = $totalSql."where keyword.memberId = ".$_SESSION["memberId"]." ";
			$totalSql = $totalSql.$this->getWhereSql();			
		}
		$totalSql = $totalSql.$this->getGroupSql();
		$totalSql = $totalSql.$this->getHavingSql();
		$totalSql = $totalSql.$this->getOrderSql();
		$resultL = mysql_query($sql);
		// ougi
		//echo $sql;	
		$rowsL = mysql_num_rows($resultL);
		$resultT = mysql_query($totalSql);
		$rowsT = mysql_num_rows($resultT);
		if($rowsL > 0)
		{	
			$fromRowNumber = $fromRow + 1;
			$toRowNumber  = $fromRowNumber + $rowsL -1;
			$this->fromToRowHtml = $fromRowNumber."件-".$toRowNumber."件";
			$this->allRowHtml =  "/".$rowsT."件";
			$this->getPageLinkHtml($rowsT);
			
			// ヘーダを取得する
			$this->tableList = $this->getHeadHtml();
			// 合計値
			$totalImp;
			$totalClick;
			$totalCtr;
			$totalCpc;
			$totalCost;
			$totalCv;
			$totalCvr;
			$totalCpa;
			$totalCpm;
			$totalRoas;
			$totalSales;
			$totalSalesValue;
			$totalClickCv;
			$totalDirect;
			$totalInDirect;
			$totalAsist;
			$totalPost;
			$totalPosition;

			
			// 表示形式を判断する
			// クリエイティブ別の場合
			if($this->reportAxis == "id")
			{
				// 標準ビューの場合
				if($this->selectView == "1" || $this->selectView == "9")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["key_Id"]."</td>";
						// 削除の場合
						if ($data["status"] == "9")
						{
							$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_deleted.gif' border='0' title='削除'></td>";
						}
						else 
						{
							// 同期済みの場合
							if($data["sync"] == "1")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_on.gif' border='0' title='同期済'></td>";
							}
							// 非同期の場合
							else if($data["sync"] == "2")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_updating.gif' border='0' title='非同期'></td>";
							}
							// エラーの場合
							else if($data["sync"] == "3")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_error.gif' border='0' title='エラー'></td>";
							}
						}
						// 削除の場合
						if ($data["status"] == "9")
						{
							$this->tableList = $this->tableList."<td>&nbsp</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td><a href='keywordEdit.php?listingType=".$data["listingType"]."&campaignId=".$data["campaignid"]."&adGroupId=".$data["adGr_ID"]."&keywordId=".$data["key_Id"]."' target='_blank'>";
							$this->tableList = $this->tableList."<img src='../images/btn_edit.gif' width='16' height='16' border='0'/></a></td>";						
						}
						$this->tableList = $this->tableList."<td align=left>".$data["keywordtext"]."</td>";
						// 掲載状態を判断する
						// 掲載中
						if($data["paused"] == "0")
						{
							$this->tableList = $this->tableList."<td align='center'>On</td>";	
						}
						// 非掲載
						else
						{
							$this->tableList = $this->tableList."<td align='center'>Off</td>";							
						}
						$this->tableList = $this->tableList."<td align=center>".$data["maxcpc"]."</td>";
						$this->tableList = $this->tableList."<td align=center>";
						$this->tableList = $this->tableList."<input type=button value=クエリワード class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='engine.php?obj=2&fromDate=".$this->fromDate."&toDate=".$this->toDate."&listingType=".$data["listingType"]."&campaignId=".$data["campaignid"]."&adgroupId=".$data["adGr_ID"]."&keywordId=".$data["key_Id"]."'\"><br>";
						$this->tableList = $this->tableList."<input type=button value=検索エンジン class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='engine.php?obj=1&fromDate=".$this->fromDate."&toDate=".$this->toDate."&listingType=".$data["listingType"]."&campaignId=".$data["campaignid"]."&adgroupId=".$data["adGr_ID"]."&keywordId=".$data["key_Id"]."'\"><br>";
						$this->tableList = $this->tableList."<input type=button value=トレンド class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.open('http://www.google.co.jp/trends/viz?q=".$data["keywordtext"]."&graph=weekly_img&sa=N')\"></td>";
						$this->tableList = $this->tableList."<td align=left>".$data["adgroupname"]."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["position"])."</td>";	
						// ougi ABCD　20081213
						if($this->selectView == "9")
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ABCD"])."</td>";	
						}					
						$this->tableList = $this->tableList."<td align=center><input type=checkbox name=sel value=".$data["key_Id"]."></td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
							$totalPosition = $totalPosition + $data["position"];
						}
						
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td></td><td></td><td></td><td align=center>【合計】</td><td></td><td></td><td></td><td></td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalPosition/$rowsT,2))."</td>";
						if($this->selectView == "9")
						{
							$this->tableList = $this->tableList."<td>-</td><td></td></tr>";
						}
						else
						{
							$this->tableList = $this->tableList."<td></td></tr>";
						}
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["key_Id"]."</td>";
						// 削除の場合
						if ($data["status"] == "9")
						{
							$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_deleted.gif' border='0' title='削除'></td>";
						}
						else 
						{
							// 同期済みの場合
							if($data["sync"] == "1")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_on.gif' border='0' title='同期済'></td>";
							}
							// 非同期の場合
							else if($data["sync"] == "2")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_updating.gif' border='0' title='非同期'></td>";
							}
							// エラーの場合
							else if($data["sync"] == "3")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_error.gif' border='0' title='エラー'></td>";
							}
						}
						// 削除の場合
						if ($data["status"] == "9")
						{
							$this->tableList = $this->tableList."<td>&nbsp</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td><a href='keywordEdit.php?listingType=".$data["listingType"]."&campaignId=".$data["campaignid"]."&adGroupId=".$data["adGr_ID"]."&keywordId=".$data["key_Id"]."' target='_blank'>";
							$this->tableList = $this->tableList."<img src='../images/btn_edit.gif' width='16' height='16' border='0'/></a></td>";						
						}
						$this->tableList = $this->tableList."<td align=left>".$data["keywordtext"]."</td>";
						// 掲載状態を判断する
						// 掲載中
						if($data["paused"] == "0")
						{
							$this->tableList = $this->tableList."<td align='center'>On</td>";	
						}
						// 非掲載
						else
						{
							$this->tableList = $this->tableList."<td align='center'>Off</td>";							
						}
						$this->tableList = $this->tableList."<td align=center>".$data["maxcpc"]."</td>";
						$this->tableList = $this->tableList."<td align=center>";
						$this->tableList = $this->tableList."<input type=button value=クエリワード class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='engine.php?obj=2&listingType=".$data["listingType"]."&campaignId=".$data["campaignid"]."&adgroupId=".$data["adGr_ID"]."&keywordId=".$data["key_Id"]."'\"><br>";
						$this->tableList = $this->tableList."<input type=button value=検索エンジン class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='engine.php?obj=1&listingType=".$data["listingType"]."&campaignId=".$data["campaignid"]."&adgroupId=".$data["adGr_ID"]."&keywordId=".$data["key_Id"]."'\"><br>";
						$this->tableList = $this->tableList."<input type=button value=トレンド class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.open('http://www.google.co.jp/trends/viz?q=".$data["keywordtext"]."&graph=weekly_img&sa=N')\"></td>";
						$this->tableList = $this->tableList."<td align=left>".$data["adgroupname"]."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=center><input type=checkbox name=sel value=".$data["key_Id"]."></td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td></td><td></td><td></td><td align=center>【合計】</td><td></td><td></td><td></td><td></td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td><td></td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td><td></td>";
						}
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["key_Id"]."</td>";
						// 削除の場合
						if ($data["status"] == "9")
						{
							$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_deleted.gif' border='0' title='削除'></td>";
						}
						else 
						{
							// 同期済みの場合
							if($data["sync"] == "1")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_on.gif' border='0' title='同期済'></td>";
							}
							// 非同期の場合
							else if($data["sync"] == "2")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_updating.gif' border='0' title='非同期'></td>";
							}
							// エラーの場合
							else if($data["sync"] == "3")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_error.gif' border='0' title='エラー'></td>";
							}
						}
						// 削除の場合
						if ($data["status"] == "9")
						{
							$this->tableList = $this->tableList."<td>&nbsp</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td><a href='keywordEdit.php?listingType=".$data["listingType"]."&campaignId=".$data["campaignid"]."&adGroupId=".$data["adGr_ID"]."&keywordId=".$data["key_Id"]."' target='_blank'>";
							$this->tableList = $this->tableList."<img src='../images/btn_edit.gif' width='16' height='16' border='0'/></a></td>";						
						}
						$this->tableList = $this->tableList."<td align=left>".$data["keywordtext"]."</td>";
						// 掲載状態を判断する
						// 掲載中
						// 掲載中
						if($data["paused"] == "0")
						{
							$this->tableList = $this->tableList."<td align='center'>On</td>";	
						}
						// 非掲載
						else
						{
							$this->tableList = $this->tableList."<td align='center'>Off</td>";							
						}
						$this->tableList = $this->tableList."<td align=center>".$data["maxcpc"]."</td>";
						$this->tableList = $this->tableList."<td align=center>";
						$this->tableList = $this->tableList."<input type=button value=クエリワード class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='engine.php?obj=2&listingType=".$data["listingType"]."&campaignId=".$data["campaignid"]."&adgroupId=".$data["adGr_ID"]."&keywordId=".$data["key_Id"]."'\"><br>";
						$this->tableList = $this->tableList."<input type=button value=検索エンジン class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='engine.php?obj=1&listingType=".$data["listingType"]."&campaignId=".$data["campaignid"]."&adgroupId=".$data["adGr_ID"]."&keywordId=".$data["key_Id"]."'\"><br>";
						$this->tableList = $this->tableList."<input type=button value=トレンド class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.open('http://www.google.co.jp/trends/viz?q=".$data["keywordtext"]."&graph=weekly_img&sa=N')\"></td>";
						$this->tableList = $this->tableList."<td align=left>".$data["adgroupname"]."</td>";						

						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=center><input type=checkbox name=sel value=".$data["key_Id"]."></td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td></td><td></td><td></td><td align=center>【合計】</td><td></td><td></td><td></td><td></td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td><td></td>";
					}
				}						
			}
			// 日別
			else if ($this->reportAxis == "d")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$data["date"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["position"])."</td></tr>";												
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
							$totalPosition = $totalPosition + $data["position"];							
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalPosition/$rowsT,2))."</td>";						
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["date"]."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$data["date"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}						
			}
			// 週別
			else if ($this->reportAxis == "w")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$this->getWeekDate($data["weekly"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["position"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
							$totalPosition = $totalPosition + $data["position"];														
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalPosition/$rowsT,2))."</td>";						
					}					
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$this->getWeekDate($data["weekly"])."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}	
					}				
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$this->getWeekDate($data["weekly"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}
			}
			// 曜日別
			else if ($this->reportAxis == "dow")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$this->getDayOfTheWeekName($data["dayOfTheWeek"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["position"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
							$totalPosition = $totalPosition + $data["position"];							
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalPosition/$rowsT,2))."</td>";												
					}					
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$this->getDayOfTheWeekName($data["dayOfTheWeek"])."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
					}					
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$this->getDayOfTheWeekName($data["dayOfTheWeek"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}
			}
			// 月別
			else if ($this->reportAxis == "m")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$data["month"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["position"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
							$totalPosition = $totalPosition + $data["position"];														
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalPosition/$rowsT,2))."</td>";																		
					}					
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["month"]."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
					}					
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$data["month"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}
			}						
		}
		// データが内の場合
		else
		{
			$this->tableList = $this->getHeadHtml();
		}
	}
	
	function getPageLinkHtml($totalRowNum)
	{
		for ($i=0;$i < $totalRowNum/$this->RECORD_NUMBER_PER_PAGE;$i++)
		{
			$pageNum = $i+1;
			$this->pageLinkHtml = $this->pageLinkHtml."<td width='10'><a href=\"javascript:document.getElementById('nowPage').value = ".$pageNum.";do_search('submit');\">"."[".$pageNum."]";
			$this->maxpage = $pageNum;
		}
	}
	
	function getHeadHtml()
	{
		// 表示形式を判断する
		// キーワード別の場合
		if($this->reportAxis == "id")
		{
			// 標準ビューの場合
			if($this->selectView == "1" || $this->selectView == "9")
			{
				$html = 	  "<td width=40 align=center>ID</td><td width=12></td><td width=10></td>";
				$html = $html."<td align=left>キーワード</td>";
				$html = $html."<td align=center>掲載</td>"; 
				$html = $html."<td align=center>入札額</td>";
				$html = $html."<td align=left></td>";
				$html = $html."<td align=center>広告グループ</td>";					 								
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td>";
				$html = $html."<td align=right>平均順位</td>";
				// ougi ABCD 20081213	
				if(	$this->selectView == "9")
				{
					$html = $html."<td align=center>ABCD分析</td>";	
				}													
				$html = $html."<td width=20 align=center><input type=checkbox onclick=\"check_all(this.checked, 'sel')\" id=sel_all></td></tr></tr>";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td width=40 align=center>ID</td><td width=12></td><td width=10></td>";
				$html = $html."<td align=left>キーワード</td>";
				$html = $html."<td align=center>掲載</td>"; 
				$html = $html."<td align=center>入札額</td>";
				$html = $html."<td align=left></td>";
				$html = $html."<td align=center>広告グループ</td>";					 								
				$html = $html."<td width=50 align=right>コスト[円]</td>";
				$html = $html."<td width=60 align=right>売上[円]</td>";
				$html = $html."<td width=50 align=right>CPC[円]</td>";
				$html = $html."<td width=50 align=right>CPM[円]</td>";
				$html = $html."<td width=50 align=right>CPA[円]</td>";
				$html = $html."<td width=50 align=right>ROAS[円]</td><td width=20 align=center>";
				$html = $html."<input type=checkbox onclick=\"check_all(this.checked, 'sel')\" id=sel_all></td></tr></tr>";				
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do								
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td width=40 align=center>ID</td><td width=12></td><td width=10></td>";
				$html = $html."<td align=left>キーワード</td>";
				$html = $html."<td align=center>掲載</td>"; 
				$html = $html."<td align=center>入札額</td>";
				$html = $html."<td align=left></td>";
				$html = $html."<td align=center>広告グループ</td>";					 								
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td><td width=20 align=center>";
				$html = $html."<input type=checkbox onclick=\"check_all(this.checked, 'sel')\" id=sel_all></td></tr></tr>";				
			}						
		}
		// 日別
		else if ($this->reportAxis == "d")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$html = 	  "<td width=40 align=center>日付</td>";
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td>";
				$html = $html."<td align=right>平均順位</td></tr>";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td width=40 align=center>日付</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td></tr>";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td width=40 align=center>日付</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}						
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$html = 	  "<td width=40 align=center>週</td>";
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td>";
				$html = $html."<td align=right>平均順位</td></tr>";				
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td align=center>週</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td></tr>";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td align=center>週</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$html = 	  "<td width=40 align=center>曜日</td>";
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td>";
				$html = $html."<td align=right>平均順位</td></tr>";				
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td width=40 align=center>曜日</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td></tr>";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td width=40 align=center>曜日</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$html = 	  "<td width=40 align=center>年月</td>";
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td>";
				$html = $html."<td align=right>平均順位</td></tr>";				
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td width=40 align=center>年月</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td></tr>";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td width=40 align=center>年月</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
		}
		return $html;
	}
	
	function getNullOutPut($value)
	{
		if($value == null || $value == "")
		{
			return "-";
		}
		else 
		{
			return round($value,2);
		}
	}
	
	function getDayOfTheWeekName($dayOfTheWeekId)
	{
		if($dayOfTheWeekId == "0")
		{
			return "日曜日";
		}
		if($dayOfTheWeekId == "1")
		{
			return "月曜日";
		}
		if($dayOfTheWeekId == "2")
		{
			return "火曜日";
		}
		if($dayOfTheWeekId == "3")
		{
			return "水曜日";
		}
		if($dayOfTheWeekId == "4")
		{
			return "木曜日";
		}
		if($dayOfTheWeekId == "5")
		{
			return "金曜日";
		}
		if($dayOfTheWeekId == "6")
		{
			return "土曜日";
		}
	}
	
	function getHavingFilter($filterCol)
	{
		// %の場合対応
		if($filterCol == "ctr")
		{
			$filterColSql = "100*sum(keywordsreport.clickCnt)/sum(keywordsreport.impression) ";
		}
		else if($filterCol == "cvr")
		{
			$filterColSql = "100*sum(keywordscvreport.cv)/sum(keywordsreport.clickCnt) ";
		}
		else if($filterCol == "cpa")
		{
			$filterColSql="sum(keywordsreport.cost)/sum(keywordscvreport.cv) ";
		}
		else if($filterCol == "roas")
		{
			$filterColSql="sum(keywordscvreport.sales)/sum(keywordsreport.cost) ";
		}
		else if($filterCol == "cpm")
		{
			$filterColSql = "1000*sum(keywordsreport.cost)/sum(keywordsreport.impression) ";
		}
		else if($filterCol == "cpc")
		{
			$filterColSql = "sum(keywordsreport.cost)/sum(keywordsreport.clickCnt) ";
		}
		else if($filterCol == "salesValue")
		{
			$filterColSql = "sum(keywordscvreport.sales)/sum(keywordscvreport.cv) ";
		}
		// sumの場合
		else
		{
			// Click-CV間隔の場合
			if($filterCol == "clickCvSpan" || $filterCol == "position")
			{
				$filterColSql = "avg(".$filterCol.") ";
			}
			else
			{
				$filterColSql = "sum(".$filterCol.") ";
			}			
		}
		
		return 	$filterColSql;
	}
	
	function setMediaList($campaignId)
	{
		session_start();
		$sql = "select listingType from campaign where camp_ID=".$campaignId." and MemberID=".$_SESSION["memberId"];
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if ($rows > 0)
		{
			$data = mysql_fetch_row($result);
			$this->searchMediaSelect = $data[0];
		}
		else
		{
			$this->searchMediaSelect = "0";
		}
	}
	
	function getWeekDate($dateTime)
	{
		$weekdate = date("Y-m-d",strtotime($dateTime));
		return $weekdate."~".strval(date("Y-m-d",strtotime($dateTime) + 24*60*60*(6))); 		
	}

	function outputCsv() 
	{
		// システム時間を取得
		$nowDate = $this->getDbDate(); 

		// ファイル名を定義
		$filename = "report_".$nowDate;
		$filename = trim($filename); 

		header("Content-Disposition: attachment; filename=".$filename.".csv"); 
		header("Content-Type:APPLICATION/csv"); 

		// タイトルを設定
		$title = $this->getCsvHeadText();
		// 内容を設定
		$content = $this->getCsvConentInfo();

		$csv = $title.$content;
		header ("Content-Length: ".(strlen($csv) +1) );

		//header("Content-Type:text/comma-separated-values"); 
		//echo $csv;
		echo mb_convert_encoding($csv,"SJIS","UTF-8");
		exit();
	}

	function getDbDate() 
	{
		$sql = "select current_date";
		$result = mysql_query($sql);		
		$rows = mysql_num_rows($result);
		if ($rows == 0) 
		{
			return "";
		} 
		else 
		{
			$nowData = mysql_fetch_row($result);
			return $nowData[0];
		}
	}

	function getCsvHeadText()
	{
		// タイトル
		$headText;
		// 表示形式を判断する
		// キャンペーン別の場合
		if($this->reportAxis == "id")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = "ID,キーワード,掲載,入札額,"
						."広告グループ,"
						."Imp,Click,CTR[%],"
						."CPC[円],コスト[円],"
						."CV,CVR[%],"
						."CPA[円],CPM[円],ROAS[円],"
						."売上[円],売上単価[円],Click-CV間隔[秒],"
						."直接,間接,アシスト,ポスト効果,平均順位"."\r\n";
			}
			// ougi ABCD分析 20081213
			else if($this->selectView == "9")
			{
				$headText = "ID,キーワード,掲載,入札額,"
						."広告グループ,"
						."Imp,Click,CTR[%],"
						."CPC[円],コスト[円],"
						."CV,CVR[%],"
						."CPA[円],CPM[円],ROAS[円],"
						."売上[円],売上単価[円],Click-CV間隔[秒],"
						."直接,間接,アシスト,ポスト効果,平均順位"."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = "ID,キーワード,掲載,入札額,"
						."広告グループ,"
						."コスト[円],売上[円],"
						."CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do								
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = "ID,キーワード,掲載,入札額,"
						."広告グループ,"
						."CV,CVR[%],売上[円],"
						."売上単価[円],Click-CV間隔[秒],直接,間接,"
						."アシスト,ポスト効果"."\r\n";
			}						
		}
		// 日別
		else if ($this->reportAxis == "d")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = "日付,Imp,Click,CTR[%],CPC[円],コスト[円],CV[円],"
					."CVR[%],CPA[円],CPM[円],ROAS[円],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果,平均順位"."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = "日付,コスト[円],売上[円],CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = "日付,CV,CVR[%],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}						
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = "週,Imp,Click,CTR[%],CPC[円],コスト[円],CV[円],"
					."CVR[%],CPA[円],CPM[円],ROAS[円],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果,平均順位"."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = "週,コスト[円],売上[円],CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = "週,CV,CVR[%],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = "曜日,Imp,Click,CTR[%],CPC[円],コスト[円],CV[円],"
					."CVR[%],CPA[円],CPM[円],ROAS[円],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果,平均順位"."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = "曜日,コス[円],売上[円],CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = "曜日,CV,CVR[%],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = "年月,Imp,Click,CTR[%],CPC[円],コスト[円],CV[円],"
					."CVR[%],CPA[円],CPM[円],ROAS[円],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果,平均順位"."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = "年月,コス[円],売上[円],CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = "年月,CV,CVR[%],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}
		}
		return $headText;
	}

	function getCsvConentInfo() 
	{
		// CSVのコンテント
		$csvContent;

		$sql = $this->getSelectSql();
		// クリエイティブ別の場合
		if($this->reportAxis == "id")
		{
			session_start();
			$sql = $sql."where campaign.camp_ID = adgroup.camp_ID ";
			$sql = $sql."and adgroup.adGr_ID = keyword.adGr_ID ";						
			$sql = $sql."and keyword.memberId = ".$_SESSION["memberId"]." ";
			$sql = $sql.$this->getWhereSqlForCreative();
		}
		else
		{
			$sql = $sql."where keyword.memberId = ".$_SESSION["memberId"]." ";			
			$sql = $sql.$this->getWhereSql();			
		}
		$sql = $sql.$this->getGroupSql();
		$sql = $sql.$this->getHavingSql();
		$sql = $sql.$this->getOrderSql();			

		$totalSql = $this->getSelectSql();
		// クリエイティブ別の場合
		if($this->reportAxis == "id")
		{
			session_start();
			$totalSql = $totalSql."where campaign.camp_ID = adgroup.camp_ID ";
			$totalSql = $totalSql."and adgroup.adGr_ID = keyword.adGr_ID ";						
			$totalSql = $totalSql."and keyword.memberId = ".$_SESSION["memberId"]." ";
			$totalSql = $totalSql.$this->getWhereSqlForCreative();
		}
		else
		{
			$totalSql = $totalSql."where keyword.memberId = ".$_SESSION["memberId"]." ";
			$totalSql = $totalSql.$this->getWhereSql();			
		}
		$totalSql = $totalSql.$this->getGroupSql();
		$totalSql = $totalSql.$this->getHavingSql();
		$totalSql = $totalSql.$this->getOrderSql();
		$resultL = mysql_query($sql);
		$rowsL = mysql_num_rows($resultL);
		$resultT = mysql_query($totalSql);
		$rowsT = mysql_num_rows($resultT);

		if($rowsL > 0)
		{
			// 合計値			
			$totalImp;
			$totalClick;
			$totalCtr;
			$totalCpc;
			$totalCost;
			$totalCv;
			$totalCvr;
			$totalCpa;
			$totalCpm;
			$totalRoas;
			$totalSales;
			$totalSalesValue;
			$totalClickCv;
			$totalDirect;
			$totalInDirect;
			$totalAsist;
			$totalPost;

			// 表示形式を判断する
			// キャンペーン別の場合
			if($this->reportAxis == "id")
			{
				// 標準ビューの場合
				if($this->selectView == "1" || $this->selectView == "9")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["key_Id"].",";
						$csvContent = $csvContent.$data["keywordtext"].",";
						// 掲載状態を判断する
						// 掲載中
						if($data["paused"] == "0")
						{
							$csvContent = $csvContent."On,";	
						}
						// 非掲載
						else
						{
							$csvContent = $csvContent."Off,";							
						}
						$csvContent = $csvContent.$data["maxcpc"].",";
						$csvContent = $csvContent.$data["adgroupname"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"]).",";						
						$csvContent = $csvContent.$this->getNullOutPut($data["position"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["key_Id"].",";
						$csvContent = $csvContent.$data["keywordtext"].",";
						// 掲載状態を判断する
						// 掲載中
						if($data["paused"] == "0")
						{
							$csvContent = $csvContent."On,";	
						}
						// 非掲載
						else
						{
							$csvContent = $csvContent."Off,";	
						}
						$csvContent = $csvContent.$data["maxcpc"].",";
						$csvContent = $csvContent.$data["adgroupname"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["key_Id"].",";
						$csvContent = $csvContent.$data["keywordtext"].",";
						// 掲載状態を判断する
						// 掲載中
						if($data["paused"] == "0")
						{
							$csvContent = $csvContent."On,";	
						}
						// 非掲載
						else
						{
							$csvContent = $csvContent."Off,";	
						}
						$csvContent = $csvContent.$data["maxcpc"].",";
						$csvContent = $csvContent.$data["adgroupname"].",";													
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}						
			}
			// 日別
			else if ($this->reportAxis == "d")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["date"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["position"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["date"].",";						
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";						
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["date"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}						
			}
			// 週別
			else if ($this->reportAxis == "w")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getWeekDate($data["weekly"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["position"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getWeekDate($data["weekly"]).",";						
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";						
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getWeekDate($data["weekly"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}	
				}
			}
			// 曜日別
			else if ($this->reportAxis == "dow")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getDayOfTheWeekName($data["dayOfTheWeek"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["position"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getDayOfTheWeekName($data["dayOfTheWeek"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";						
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getDayOfTheWeekName($data["dayOfTheWeek"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}			
			}
			// 月別
			else if ($this->reportAxis == "m")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["month"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["position"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["month"].",";						
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";
					}					
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["month"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}
			}
			// 標準ビューの場合
			if($this->selectView == "1" || $this->selectView == "9") {
				for ($i=0;$i<$rowsT;$i++)
				{

					$data = mysql_fetch_array($resultT);
					// 合計値を計算する
					$totalImp = $totalImp + $data["impression"];
					$totalClick = $totalClick + $data["clickCnt"];
					$totalCost = $totalCost + $data["cost"];
					$totalCv = $totalCv + $data["cv"];
					$totalSales = $totalSales + $data["sales"];
					$totalSalesValue = $totalSalesValue + $data["salesValue"];
					$totalClickCv = $totalClickCv + $data["clickCvSpan"];
					$totalDirect = $totalDirect + $data["directCvCnt"];
					$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
					$totalAsist = $totalAsist + $data["asistCvCnt"];
					$totalPost = $totalPost + $data["postCvCnt"];
					$totalPosition = $totalPosition + $data["position"];
				}

				// 合計の内容を追加する
				// キャンペーン別の場合
				if($this->reportAxis == "id") {
					$csvContent = $csvContent.",,,合計,,";
				} else {
					$csvContent = $csvContent."合計,";
				}
				$csvContent = $csvContent.$this->getNullOutPut($totalImp).",".$this->getNullOutPut($totalClick).",";
				if($totalImp == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(100*$totalClick/$totalImp,2)).",";						
				}						
				// cpc
				if($totalClick == 0)
				{
					$csvContent = $csvContent."-,";	
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalCost/$totalClick,2)).",";
				}
				$csvContent = $csvContent.$this->getNullOutPut($totalCost).",";
				
				
				$csvContent = $csvContent.$this->getNullOutPut($totalCv).",";
				// cvr
				if($totalClick == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(100*$totalCv/$totalClick,2)).",";
				}

					
				// cpa
				if($totalCv == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalCost/$totalCv,2)).",";
				}

				// cpm
				if($totalImp == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(1000*$totalCost/$totalImp,2)).",";
				}
				// roas
				if($totalCost == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalSales/$totalCost,2)).",";
				}
				

				$csvContent = $csvContent.$this->getNullOutPut($totalSales).",";
				// salesValue
				if($totalCv == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalSales/$totalCv,2)).",";
				}
				$csvContent = $csvContent.$this->getNullOutPut(round($totalClickCv/$rowsT,2)).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalDirect).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalInDirect).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalAsist).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalPost).",";
				$csvContent = $csvContent.$this->getNullOutPut(round($totalPosition/$rowsT,2))."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				for ($i=0;$i<$rowsT;$i++)
				{
					$data = mysql_fetch_array($resultT);
					// 合計値を計算する
					$totalImp = $totalImp + $data["impression"];
					$totalClick = $totalClick + $data["clickCnt"];
					$totalCost = $totalCost + $data["cost"];
					$totalCv = $totalCv + $data["cv"];
					$totalSales = $totalSales + $data["sales"];
					$totalSalesValue = $totalSalesValue + $data["salesValue"];
					$totalClickCv = $totalClickCv + $data["clickCvSpan"];
					$totalDirect = $totalDirect + $data["directCvCnt"];
					$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
					$totalAsist = $totalAsist + $data["asistCvCnt"];
					$totalPost = $totalPost + $data["postCvCnt"];
				}
				// 合計のhtmlを追加する
				// キャンペーン別の場合
				if($this->reportAxis == "id") {
					$csvContent = $csvContent.",,合計,,,";
				} else {
					$csvContent = $csvContent."合計,";
				}
				$csvContent = $csvContent.$this->getNullOutPut($totalCost).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalSales).",";					
				// cpc
				if($totalClick == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalCost/$totalClick,2)).",";
				}					
				// cpm
				if($totalImp == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(1000*$totalCost/$totalImp,2)).",";
				}
				// cpa
				if($totalCv == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalCost/$totalCv,2)).",";
				}
				// roas
				if($totalCost == 0)
				{
					$csvContent = $csvContent."-"."\r\n";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalSales/$totalCost,2))."\r\n";
				}
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				for ($i=0;$i<$rowsT;$i++)
				{
					$data = mysql_fetch_array($resultT);
					// 合計値を計算する
					$totalCv = $totalCv + $data["cv"];
					$totalClick = $totalClick + $data["clickCnt"];
					$totalSales = $totalSales + $data["sales"];
					$totalSalesValue = $totalSalesValue + $data["salesValue"];
					$totalClickCv = $totalClickCv + $data["clickCvSpan"];
					$totalDirect = $totalDirect + $data["directCvCnt"];
					$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
					$totalAsist = $totalAsist + $data["asistCvCnt"];
					$totalPost = $totalPost + $data["postCvCnt"];
				}
				// 合計のhtmlを追加する
				// キャンペーン別の場合
				if($this->reportAxis == "id") {
					$csvContent = $csvContent.",,合計,,,";
				} else {
					$csvContent = $csvContent."合計,";
				}
				
				$csvContent = $csvContent.$this->getNullOutPut($totalCv).",";
				// cvr
				if($totalClick == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(100*$totalCv/$totalClick,2)).",";
				}
				$csvContent = $csvContent.$this->getNullOutPut($totalSales).",";
				// salesValue
				if($totalCv == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalSales/$totalCv,2)).",";
				}
				$csvContent = $csvContent.$this->getNullOutPut(round($totalClickCv/$rowsT,2)).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalDirect).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalInDirect).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalAsist).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalPost)."\r\n";
			}
			
		}
		return $csvContent;
	}
	
	// ougi 20081213 CPAの平均値を取得
	function getAvgCPA()
	{
		session_start();
		$sql = "select if(sum(keywordsreport.cost)/sum(keywordscvreport.cv) is null,0,sum(keywordsreport.cost)/sum(keywordscvreport.cv)) as avgCPA ";
		$sql = $sql." from keyword left join keywordscvreport on keyword.key_Id = keywordscvreport.keyword_id  ";
		$sql = $sql."and TO_DAYS('".$this->fromDate."')<=TO_DAYS(keywordscvreport.date) ";			
		$sql = $sql."and TO_DAYS(keywordscvreport.date)<=TO_DAYS('".$this->toDate."') " ;
		$sql = $sql."left join keywordsreport ";
		$sql = $sql."on keywordscvreport.date = keywordsreport.date ";
		$sql = $sql."and keywordscvreport.memberid = keywordsreport.memberId ";	
		$sql = $sql."and keywordscvreport.listingtype = keywordsreport.listingType ";
		$sql = $sql."and keywordscvreport.campaign_id = keywordsreport.campaign_Id ";
		$sql = $sql."and keywordscvreport.adGroup_id = keywordsreport.adGroup_Id ";
		$sql = $sql."and keywordscvreport.keyword_id = keywordsreport.keyword_id ";
		$sql = $sql."where keyword.memberId = ".$_SESSION["memberId"]." ";	
		$sql = $sql."and  keyword.status <>9 ";	
		
		$result = mysql_query($sql);
		//echo $sql;
		$rows = mysql_num_rows($result);
		if ($rows > 0)
		{
			$data = mysql_fetch_row($result);	
			return $data[0];		
		}else
		{
			return 0;
		}
	}

	function getKwTableList(){
		$sql = "SELECT keywordName,note,SUM(point) FROM DailyKeywordRakning WHERE date>='".$this->fromDate."' AND date<='".$this->toDate."' GROUP BY keywordName ORDER BY point desc LIMIT 0,30;";
		$result = mysql_query($sql);

		if(!$result || mysql_num_rows($result)==0){
			return "選択された期間に該当する急上昇キーワードランキングは存在しません。<br/>前日の急上昇キーワードランキングは、当日14:00に反映されます。";
			//exit;
		}
		
		$table_header = "<table width=\"100%\" border=\"0\"><tr><td colspan=\"2\">急上昇キーワードランキング </td></tr><tr><td>";
		
		$table_disp = $table_header."<table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" class=\"tbl\">";
		$rank = 1;
		while($row = mysql_fetch_array($result)){
			
			if($rank<=15){
				$class = $rank%2==0 ? "tr4" : "tr3";
				$table_disp .= "<tr  class=\"$class\"><td  width=\"40\" class=\"td2_2\">".$rank."</td><td>".$row['keywordName']."<br />".$row['note']."</td></tr>";
			}else{
				$class = $rank%2==0 ? "tr3" : "tr4";
				$table_disp2 .= "<tr  class=\"$class\"><td  width=\"40\"  class=\"td2_2\">".$rank."</td><td>".$row['keywordName']."<br />".$row['note']."</td></tr>";
			}
			$rank++;
		}

		$table_disp .= "</table></td><td>"."<table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" class=\"tbl\">".$table_disp2."</table></td></tr></table>";
		return $table_disp;
	}

}
?>